<!DOCTYPE >
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>成都军区总医院his后台系统</title>
        <link rel="stylesheet" type="text/css" href="../login.css"/>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.js"></script>
	</head>

	<body>
        <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
        <!-- 引入组件库 -->
        <script src="https://unpkg.com/element-ui/lib/index.js"></script>
        <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
      
	<div id="content">		
		<h4 >欢迎登录HIS系统</h4><br />
		<form action="/login" method="get" >
			<input type="text" name="username" id="username" placeholder="请输入账号" /><br /><br />
			<input type="password" name="password" id="password" placeholder="请输入密码" /><br /><br />
			<input type="button" name="denglu" id="denglu" onclick="sub" value="登录" />
		</form>
        <p id="forget">忘记密码?</p><br>
        <div style="margin-top: -20px;" id="forg">
            <input type="text" id="email" placeholder="请输入邮箱">&nbsp;<input type="button" id="send" value="发送">
        </div>
        <div style="margin-top: 10px;" id="res">
            <input type="text" id="activecode" placeholder="请输入验证码">&nbsp;<input type="button" id="reset" value="重置">
        </div>
        
        
    </div>
        
  
  
    <script>
        
       $(function(){
           $("#denglu").click(function(){
                console.log(document.getElementById("username").value)
                axios.get("http://localhost:8088/login",{params:{
                    username:$("#username").val(),
                    password:$("#password").val()
                }})
                .then(res =>{
                    console.log(res.data)
                    if(res.data.success==true){
                        localStorage.setItem("loginFlag",res.data.data.password)
                        location.href="http://localhost:8080/#/"
                    }
                    alert(res.data.message)
                })
                .catch(err =>{
                    console.log(err)
                })
            })
            $("#forget").click(function(){
                $("#forg").css("visibility","visible");
            })
            $("#send").click(function(){
                // 将这个按钮设为不可点击
                $("#send").attr('disabled',true);
                $("#res").css("visibility","visible");
               var i=10
               var interval= setInterval(function(){
                    i--;
                    $("#send").val(i)
                    if(i<=0){
                        clearInterval(interval);
                        $("#send").attr('disabled',false);
                        $("#send").val("发送")
                    }
                },1000);
                
                axios.get("http://localhost:8088/email",{params:{email:$("#email").val()}})
                .then(resp =>{
                    console.log(resp.data.message)
                    if(resp.data.success==true){
                        alert("成功找到")
                        localStorage.setItem("doctorId",resp.data.data.doctorId)
                        console.log("医生id为"+resp.data.data.doctorId)
                    }else{
                        alert("未找到该邮箱")
                    }
                })
                .catch(err =>{
                    console.log(err.data)
                })
            })
        
            $("#reset").click(function(){
                console.log(localStorage.getItem("doctorId"))
                axios.get("http://localhost:8088/reset",{params:{
                    doctorId:localStorage.getItem("doctorId"),
                    activeCode:$("#activecode").val()
                }})
                .then(resp =>{
                    alert(resp.data.message)
                })
                .catch(err =>{
                    console.log(err.data)
                })
            })


       })
         

    </script>
     
    </body>
    </html>